package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductIssueDAO;
import com.ourteam.product.requirement.dao.ProductIssue;
import com.ourteam.product.requirement.dao.ProductIssueDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:43
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductIssueDAOJdbcImpl extends AbstractSpringDAO
    implements IProductIssueDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ProductDefineId, ProductVersionId, IssueCode, IssueType,
            IssueTitle, IssueContent, IssuePriority, SubmitUserId, SubmitTime,
            AssignUserId, AssignTime, PlanSolveTime, ActualSolveTime,
            Resolutions, ResolutionsRemarks, LastUpdateTime, LastUpdateUserId,
            IssueNoteCount, IssueAttachCount, Status, Remarks, CreatorId,
            CreateTime, CreatorName, CreatorPhoto
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ProductDefineId,
            _DataObjectProperty.ProductVersionId, _DataObjectProperty.IssueCode,
            _DataObjectProperty.IssueType, _DataObjectProperty.IssueTitle,
            _DataObjectProperty.IssueContent, _DataObjectProperty.IssuePriority,
            _DataObjectProperty.SubmitUserId, _DataObjectProperty.SubmitTime,
            _DataObjectProperty.AssignUserId, _DataObjectProperty.AssignTime,
            _DataObjectProperty.PlanSolveTime,
            _DataObjectProperty.ActualSolveTime, _DataObjectProperty.Resolutions,
            _DataObjectProperty.ResolutionsRemarks,
            _DataObjectProperty.LastUpdateTime,
            _DataObjectProperty.LastUpdateUserId,
            _DataObjectProperty.IssueNoteCount,
            _DataObjectProperty.IssueAttachCount, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.CreatorId,
            _DataObjectProperty.CreateTime, _DataObjectProperty.CreatorName,
            _DataObjectProperty.CreatorPhoto
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductIssue, ProductIssueDAOQueryBean> daoHelper;

    public AbstractProductIssueDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductIssue, ProductIssueDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" RELATED_R1XX81_SysUser ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "RELATED_R1XX81_SysUser."));
            relatedJoinSQLBuffer.append(" = ").append(CreatorId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductIssue
         * @throws Exception
         */
    public boolean checkIsUnique(ProductIssue aProductIssue)
        throws Exception {
        if (aProductIssue == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductIssue.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductIssue
     * @throws Exception
     */
    public void insert(ProductIssue aProductIssue) throws Exception {
        super.doInsert(aProductIssue);
    }

    /**
         * Batch Insert Datas
         * @param aProductIssue
         * @throws Exception
         */
    public void batchInsert(ProductIssue[] aProductIssues)
        throws Exception {
        super.doBatchInsert(aProductIssues);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductIssueDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductIssue aProductIssue) throws Exception {
        delete(aProductIssue.getId());
    }

    /**
     * Update Data Selective
     * @param aProductIssue
     * @throws Exception
     */
    public void update(ProductIssue aProductIssue) throws Exception {
        if (aProductIssue.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductIssue);

        ProductIssue tempObj = findById(aProductIssue.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductIssue, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductIssues[]
     * @throws Exception
     */
    public void batchUpdate(ProductIssue[] aProductIssues)
        throws Exception {
        super.doBatchUpdate(aProductIssues);
    }

    /**
         * Update Data By Condictions
         * @param aProductIssue
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductIssue aProductIssue,
        ProductIssueDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductIssue, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductIssueDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductIssue aProductIssue)
        throws Exception {
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductIssue findById(final long id) throws Exception {
        ProductIssueDAOQueryBean queryBean = new ProductIssueDAOQueryBean();

        ProductIssueDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductIssue[] ProductIssues = query(queryBean);

        if (ProductIssues.length == 0) {
            return null;
        } else {
            return ProductIssues[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductIssue[]
         * @throws Exception
         */
    public ProductIssue[] query(ProductIssueDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean, new JdbcProductIssueRowMapper());

        return (ProductIssue[]) result.toArray(new ProductIssue[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductIssueDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductIssueDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductIssue[] aProductIssues,
        ProductIssueDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductIssues, queryBean);
    }

    public void synchronize(ProductIssue[] aProductIssues,
        ProductIssueDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductIssue> callBack)
        throws Exception {
        daoHelper.synchronize(aProductIssues, queryBean, callBack);
    }

    public static class JdbcProductIssueRowMapper implements RowMapper<ProductIssue> {
        public ProductIssue mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductIssue object = new ProductIssue();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object productDefineId = null;

                productDefineId = resultSet.getObject(columnIndex++);

                object.setProductDefineIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productDefineId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductDefineId,
                        productDefineId);
                }

                Object productVersionId = null;

                productVersionId = resultSet.getObject(columnIndex++);

                object.setProductVersionIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (productVersionId != null) {
                    setBeanValue(object, _DataObjectProperty.ProductVersionId,
                        productVersionId);
                }

                Object issueCode = null;

                issueCode = resultSet.getObject(columnIndex++);

                object.setIssueCodeNull(resultSet.getBoolean(columnIndex++));

                if (issueCode != null) {
                    setBeanValue(object, _DataObjectProperty.IssueCode,
                        issueCode);
                }

                Object issueType = null;

                issueType = resultSet.getObject(columnIndex++);

                object.setIssueTypeNull(resultSet.getBoolean(columnIndex++));

                if (issueType != null) {
                    setBeanValue(object, _DataObjectProperty.IssueType,
                        issueType);
                }

                Object issueTitle = null;

                issueTitle = resultSet.getObject(columnIndex++);

                object.setIssueTitleNull(resultSet.getBoolean(columnIndex++));

                if (issueTitle != null) {
                    setBeanValue(object, _DataObjectProperty.IssueTitle,
                        issueTitle);
                }

                Object issueContent = null;

                issueContent = resultSet.getObject(columnIndex++);

                object.setIssueContentNull(resultSet.getBoolean(columnIndex++));

                if (issueContent != null) {
                    setBeanValue(object, _DataObjectProperty.IssueContent,
                        issueContent);
                }

                Object issuePriority = null;

                issuePriority = resultSet.getObject(columnIndex++);

                object.setIssuePriorityNull(resultSet.getBoolean(columnIndex++));

                if (issuePriority != null) {
                    setBeanValue(object, _DataObjectProperty.IssuePriority,
                        issuePriority);
                }

                Object submitUserId = null;

                submitUserId = resultSet.getObject(columnIndex++);

                object.setSubmitUserIdNull(resultSet.getBoolean(columnIndex++));

                if (submitUserId != null) {
                    setBeanValue(object, _DataObjectProperty.SubmitUserId,
                        submitUserId);
                }

                Object submitTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    submitTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    submitTime = resultSet.getObject(columnIndex++);
                }

                object.setSubmitTimeNull(resultSet.getBoolean(columnIndex++));

                if (submitTime != null) {
                    setBeanValue(object, _DataObjectProperty.SubmitTime,
                        submitTime);
                }

                Object assignUserId = null;

                assignUserId = resultSet.getObject(columnIndex++);

                object.setAssignUserIdNull(resultSet.getBoolean(columnIndex++));

                if (assignUserId != null) {
                    setBeanValue(object, _DataObjectProperty.AssignUserId,
                        assignUserId);
                }

                Object assignTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    assignTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    assignTime = resultSet.getObject(columnIndex++);
                }

                object.setAssignTimeNull(resultSet.getBoolean(columnIndex++));

                if (assignTime != null) {
                    setBeanValue(object, _DataObjectProperty.AssignTime,
                        assignTime);
                }

                Object planSolveTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    planSolveTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    planSolveTime = resultSet.getObject(columnIndex++);
                }

                object.setPlanSolveTimeNull(resultSet.getBoolean(columnIndex++));

                if (planSolveTime != null) {
                    setBeanValue(object, _DataObjectProperty.PlanSolveTime,
                        planSolveTime);
                }

                Object actualSolveTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    actualSolveTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    actualSolveTime = resultSet.getObject(columnIndex++);
                }

                object.setActualSolveTimeNull(resultSet.getBoolean(
                        columnIndex++));

                if (actualSolveTime != null) {
                    setBeanValue(object, _DataObjectProperty.ActualSolveTime,
                        actualSolveTime);
                }

                Object resolutions = null;

                resolutions = resultSet.getObject(columnIndex++);

                object.setResolutionsNull(resultSet.getBoolean(columnIndex++));

                if (resolutions != null) {
                    setBeanValue(object, _DataObjectProperty.Resolutions,
                        resolutions);
                }

                Object resolutionsRemarks = null;

                resolutionsRemarks = resultSet.getObject(columnIndex++);

                object.setResolutionsRemarksNull(resultSet.getBoolean(
                        columnIndex++));

                if (resolutionsRemarks != null) {
                    setBeanValue(object,
                        _DataObjectProperty.ResolutionsRemarks,
                        resolutionsRemarks);
                }

                Object lastUpdateTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    lastUpdateTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    lastUpdateTime = resultSet.getObject(columnIndex++);
                }

                object.setLastUpdateTimeNull(resultSet.getBoolean(columnIndex++));

                if (lastUpdateTime != null) {
                    setBeanValue(object, _DataObjectProperty.LastUpdateTime,
                        lastUpdateTime);
                }

                Object lastUpdateUserId = null;

                lastUpdateUserId = resultSet.getObject(columnIndex++);

                object.setLastUpdateUserIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (lastUpdateUserId != null) {
                    setBeanValue(object, _DataObjectProperty.LastUpdateUserId,
                        lastUpdateUserId);
                }

                Object issueNoteCount = null;

                issueNoteCount = resultSet.getObject(columnIndex++);

                object.setIssueNoteCountNull(resultSet.getBoolean(columnIndex++));

                if (issueNoteCount != null) {
                    setBeanValue(object, _DataObjectProperty.IssueNoteCount,
                        issueNoteCount);
                }

                Object issueAttachCount = null;

                issueAttachCount = resultSet.getObject(columnIndex++);

                object.setIssueAttachCountNull(resultSet.getBoolean(
                        columnIndex++));

                if (issueAttachCount != null) {
                    setBeanValue(object, _DataObjectProperty.IssueAttachCount,
                        issueAttachCount);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object creatorId = null;

                creatorId = resultSet.getObject(columnIndex++);

                object.setCreatorIdNull(resultSet.getBoolean(columnIndex++));

                if (creatorId != null) {
                    setBeanValue(object, _DataObjectProperty.CreatorId,
                        creatorId);
                }

                Object createTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    createTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    createTime = resultSet.getObject(columnIndex++);
                }

                object.setCreateTimeNull(resultSet.getBoolean(columnIndex++));

                if (createTime != null) {
                    setBeanValue(object, _DataObjectProperty.CreateTime,
                        createTime);
                }

                Object creatorName = null;

                creatorName = resultSet.getObject(columnIndex++);

                object.setCreatorNameNull(resultSet.getBoolean(columnIndex++));

                if (creatorName != null) {
                    setBeanValue(object, _DataObjectProperty.CreatorName,
                        creatorName);
                }

                Object creatorPhoto = null;

                creatorPhoto = resultSet.getObject(columnIndex++);

                object.setCreatorPhotoNull(resultSet.getBoolean(columnIndex++));

                if (creatorPhoto != null) {
                    setBeanValue(object, _DataObjectProperty.CreatorPhoto,
                        creatorPhoto);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
